package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DosingType;
import com.ruoyi.system.service.IDosingTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 备料类型Controller
 * 
 * @author ruoyi
 * @date 2025-02-13
 */
@RestController
@RequestMapping("/system/type")
@Api(tags = "备料类型管理")
public class DosingTypeController extends BaseController
{
    @Autowired
    private IDosingTypeService dosingTypeService;

    /**
     * 查询备料类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    @ApiOperation("查询备料类型列表")
    public TableDataInfo list(@RequestBody DosingType dosingType, @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize)
    {
        List<DosingType> list = dosingTypeService.selectDosingTypeList(dosingType, pageNum, pageSize);
        Long total = dosingTypeService.selectDosingTypeCount(dosingType);
        return getDataTable(list, total);
    }

    /**
     * 导出备料类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "备料类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出备料类型列表")
    public void export(HttpServletResponse response, DosingType dosingType)
    {
        List<DosingType> list = dosingTypeService.selectDosingTypeAll(dosingType);
        ExcelUtil<DosingType> util = new ExcelUtil<DosingType>(DosingType.class);
        util.exportExcel(response, list, "备料类型数据");
    }

    /**
     * 获取备料类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取备料类型详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dosingTypeService.selectDosingTypeById(id));
    }

    /**
     * 新增备料类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "备料类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ApiOperation("新增备料类型")
    public AjaxResult add(@RequestBody DosingType dosingType)
    {
        return toAjax(dosingTypeService.insertDosingType(dosingType));
    }

    /**
     * 修改备料类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "备料类型", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    @ApiOperation("修改备料类型")
    public AjaxResult edit(@RequestBody DosingType dosingType)
    {
        return toAjax(dosingTypeService.updateDosingType(dosingType));
    }

    /**
     * 删除备料类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "备料类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除备料类型")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dosingTypeService.deleteDosingTypeByIds(ids));
    }
}
